//
// Created by xili on 2024/8/3 14:56.
// Go big or go home.
//
#include <unordered_map>

using namespace std;

class Solution {
public:
    int countLargestGroup(int n) {
        unordered_map<int, int> ump;
        int m = 0;
        for (int i = 1; i <= n; i++) {
            int val = i;
            int sum = 0;
            while (val) {
                sum += val % 10;
                val /= 10;
            }
            ump[sum]++;
            m = max(m, ump[sum]);
        }
        int ans = 0;
        for (auto &item: ump) {
            if (item.second == m) {
                ans++;
            }
        }
        return ans;
    }
};